home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / cupspk.py < prev    next >
Text File  |  2009-10-19  |  29KB  |  813 lines

  1. # vim: set ts=4 sw=4 et: coding=UTF-8
  2. #
  3. # Copyright (C) 2008 Novell, Inc.
  4. # Copyright (C) 2008, 2009 Red Hat, Inc.
  5. # Copyright (C) 2008, 2009 Tim Waugh <twaugh@redhat.com>
  6. #
  7. # Authors: Vincent Untz
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. #
  23.  
  24. # check FIXME/TODO here
  25. # check FIXME/TODO in cups-pk-helper
  26. # define fine-grained policy (more than one level of permission)
  27. # add missing methods
  28.  
  29. import os
  30. import sys
  31.  
  32. import tempfile
  33.  
  34. import cups
  35. import dbus
  36. import gtk
  37. from debug import debugprint
  38.  
  39. from dbus.mainloop.glib import DBusGMainLoop
  40. DBusGMainLoop(set_as_default=True)
  41.  
  42. PK_AUTH_NAME  = 'org.freedesktop.PolicyKit.AuthenticationAgent'
  43. PK_AUTH_PATH  = '/org/gnome/PolicyKit/Manager'
  44. PK_AUTH_IFACE = 'org.freedesktop.PolicyKit.AuthenticationAgent'
  45.  
  46. CUPS_PK_NAME  = 'org.opensuse.CupsPkHelper.Mechanism'
  47. CUPS_PK_PATH  = '/'
  48. CUPS_PK_IFACE = 'org.opensuse.CupsPkHelper.Mechanism'
  49.  
  50. CUPS_PK_NEED_AUTH = 'org.opensuse.CupsPkHelper.Mechanism.NotPrivileged'
  51.  
  52.  
  53. pk_auth_ret = False
  54. pk_auth_error = None
  55. pk_auth_running = False
  56. pk_auth_done = False
  57.  
  58. def _pk_auth_reply_handler(ret):
  59.     global pk_auth_ret
  60.     global pk_auth_done
  61.  
  62.     pk_auth_ret = ret
  63.     pk_auth_done = True
  64.  
  65. def _pk_auth_error_handler(e):
  66.     global pk_auth_error
  67.     global pk_auth_done
  68.  
  69.     pk_auth_error = str(e)
  70.     pk_auth_done = True
  71.  
  72.  
  73. # we can't subclass cups.Connection, even when adding
  74. # Py_TPFLAGS_BASETYPE to cupsconnection.c
  75. # So we'll hack this...
  76. class Connection:
  77.     def __init__(self, host, port, encryption):
  78.         self._parent = None
  79.  
  80.         try:
  81.             self._session_bus = dbus.SessionBus()
  82.             self._system_bus = dbus.SystemBus()
  83.         except dbus.exceptions.DBusException:
  84.             # One or other bus not running.
  85.             self._session_bus = self._system_bus = None
  86.  
  87.         self._connection = cups.Connection(host=host,
  88.                                            port=port,
  89.                                            encryption=encryption)
  90.  
  91.         self._hack_subclass()
  92.  
  93.  
  94.     def _hack_subclass(self):
  95.         # here's how to subclass without really subclassing. Just provide
  96.         # the same methods
  97.         methodtype = type(self._connection.getPrinters)
  98.         for fname in dir(self._connection):
  99.             if fname[0] == '_':
  100.                 continue
  101.             fn = getattr(self._connection, fname)
  102.             if type(fn) != methodtype:
  103.                 continue
  104.             if not hasattr(self, fname):
  105.                 setattr(self, fname, fn.__call__)
  106.  
  107.  
  108.     def set_parent(self, parent):
  109.         self._parent = parent
  110.  
  111.  
  112.     def _get_cups_pk(self):
  113.         try:
  114.             object = self._system_bus.get_object(CUPS_PK_NAME, CUPS_PK_PATH)
  115.             return dbus.Interface(object, CUPS_PK_IFACE)
  116.         except dbus.exceptions.DBusException:
  117.             # Failed to get object or interface.
  118.             return None
  119.         except AttributeError:
  120.             # No system D-Bus
  121.             return None
  122.  
  123.  
  124.     def _obtain_auth(self, action, xid = 0):
  125.         global pk_auth_ret
  126.         global pk_auth_error
  127.         global pk_auth_done
  128.         global pk_auth_running
  129.  
  130.         if pk_auth_running:
  131.             # FIXME: raise an exception: this should really never happen
  132.             return False
  133.  
  134.         pk_auth_ret = False
  135.         pk_auth_error = None
  136.         pk_auth_done = False
  137.  
  138.         pk_auth_object = self._session_bus.get_object(PK_AUTH_NAME, PK_AUTH_PATH)
  139.         pk_auth = dbus.Interface(pk_auth_object, PK_AUTH_IFACE)
  140.  
  141.         # We're doing this dbus call asynchronously because we want to not
  142.         # freeze the UI while a menu is being destroyed. And the windows might
  143.         # need some repainting while the authorization dialog is displayed.
  144.         pk_auth_running = True
  145.  
  146.         pk_auth.ObtainAuthorization(action, dbus.UInt32(xid), dbus.UInt32(os.getpid()), reply_handler=_pk_auth_reply_handler, error_handler=_pk_auth_error_handler, timeout=2**31/1000)
  147.  
  148.         while not pk_auth_done:
  149.             gtk.main_iteration(True)
  150.  
  151.         pk_auth_running = False
  152.  
  153.         if pk_auth_error != None:
  154.             if pk_auth_error.find('org.freedesktop.DBus.Error.NoReply') == 0:
  155.                 return False
  156.             raise dbus.exceptions.DBusException(pk_auth_error)
  157.  
  158.         if not type(pk_auth_ret) == dbus.Boolean:
  159.             return False
  160.  
  161.         return pk_auth_ret != 0
  162.  
  163.  
  164.     def _handle_exception_with_auth(self, e):
  165.         if e.get_dbus_name() != CUPS_PK_NEED_AUTH:
  166.             return False
  167.  
  168.         tokens = e.get_dbus_message().split(' ', 2)
  169.         if len(tokens) != 3:
  170.             return False
  171.  
  172.         try:
  173.             xid = 0
  174.             if self._parent and getattr(self._parent, 'window') and getattr(self._parent.window, 'xid'):
  175.                 xid = self._parent.window.xid
  176.  
  177.             # FIXME: is xid working?
  178.             ret = self._obtain_auth(tokens[0], xid)
  179.         except dbus.exceptions.DBusException:
  180.             return False
  181.  
  182.         if not ret:
  183.             raise cups.IPPError(cups.IPP_NOT_AUTHORIZED, 'pkcancel')
  184.  
  185.         return True
  186.  
  187.  
  188.     def _call_with_pk_and_fallback(self, use_fallback, pk_function_name, pk_args, fallback_function, *args, **kwds):
  189.         pk_function = None
  190.  
  191.         if not use_fallback:
  192.             cups_pk = self._get_cups_pk()
  193.             if cups_pk:
  194.                 try:
  195.                     pk_function = cups_pk.get_dbus_method(pk_function_name)
  196.                 except dbus.exceptions.DBusException:
  197.                     pass
  198.  
  199.         if use_fallback or not pk_function:
  200.             return fallback_function(*args, **kwds)
  201.  
  202.         pk_retval = 'PolicyKit communication issue'
  203.  
  204.         while True:
  205.             try:
  206.                 # FIXME: async call or not?
  207.                 pk_retval = pk_function(*pk_args)
  208.  
  209.                 # if the PK call has more than one return values, we pop the
  210.                 # first one as the error message
  211.                 if type(pk_retval) == tuple:
  212.                     retval = pk_retval[1:]
  213.                     # if there's no error, then we can safely return what we
  214.                     # got
  215.                     if pk_retval[0] == '':
  216.                         # if there's only one item left in the tuple, we don't
  217.                         # want to return the tuple, but the item
  218.                         if len(retval) == 1:
  219.                             return retval[0]
  220.                         else:
  221.                             return retval
  222.                 break
  223.             except dbus.exceptions.DBusException, e:
  224.                 if not self._handle_exception_with_auth(e):
  225.                     break
  226.  
  227.         # The PolicyKit call did not work (either a PK-error and we got a dbus
  228.         # exception that wasn't handled, or an error in the mechanism itself)
  229.         if pk_retval != '':
  230.             debugprint ('PolicyKit call to %s did not work: %s' %
  231.                         (pk_function_name, pk_retval))
  232.             return fallback_function(*args, **kwds)
  233.  
  234.  
  235.     def _args_to_tuple(self, types, *args):
  236.         retval = [ False ]
  237.  
  238.         if len(types) != len(args):
  239.             retval[0] = True
  240.             # We do this to have the right length for the returned value
  241.             retval.extend(types)
  242.             return tuple(types)
  243.  
  244.         exception = False
  245.  
  246.         for i in range(len(types)):
  247.             if type(args[i]) != types[i]:
  248.                 if types[i] == str and type(args[i]) == unicode:
  249.                     # we accept a mix between unicode and str
  250.                     pass
  251.                 elif types[i] == str and type(args[i]) == int:
  252.                     # we accept a mix between int and str
  253.                     retval.append(str(args[i]))
  254.                     continue
  255.                 elif types[i] == str and type(args[i]) == float:
  256.                     # we accept a mix between float and str
  257.                     retval.append(str(args[i]))
  258.                     continue
  259.                 elif types[i] == str and type(args[i]) == bool:
  260.                     # we accept a mix between bool and str
  261.                     retval.append(str(args[i]))
  262.                     continue
  263.                 elif types[i] == str and args[i] == None:
  264.                     # None is an empty string for dbus
  265.                     retval.append('')
  266.                     continue
  267.                 elif types[i] == list and type(args[i]) == tuple:
  268.                     # we accept a mix between list and tuple
  269.                     retval.append(list(args[i]))
  270.                     continue
  271.                 elif types[i] == list and args[i] == None:
  272.                     # None is an empty list
  273.                     retval.append([])
  274.                     continue
  275.                 else:
  276.                     exception = True
  277.             retval.append(args[i])
  278.  
  279.         retval[0] = exception
  280.  
  281.         return tuple(retval)
  282.  
  283.  
  284.     def _kwds_to_vars(self, names, **kwds):
  285.         ret = []
  286.  
  287.         for name in names:
  288.             if kwds.has_key(name):
  289.                 ret.append(kwds[name])
  290.             else:
  291.                 ret.append('')
  292.  
  293.         return tuple(ret)
  294.  
  295.  
  296. #    getPrinters
  297. #    getDests
  298. #    getClasses
  299. #    getPPDs
  300. #    getServerPPD
  301. #    getDocument
  302.  
  303.  
  304.     def getDevices(self, *args, **kwds):
  305.         use_pycups = False
  306.  
  307.         timeout = 0
  308.         include_schemes = ''
  309.         exclude_schemes = ''
  310.  
  311.         if len(args) == 3:
  312.             (use_pycups, timeout, include_schemes, exclude_schemes) = self._args_to_tuple([int, str, str], *args)
  313.         else:
  314.             if kwds.has_key('timeout'):
  315.                 timeout = kwds['timeout']
  316.  
  317.             if kwds.has_key('include_schemes'):
  318.                 include_schemes = kwds['include_schemes']
  319.  
  320.             if kwds.has_key('exclude_schemes'):
  321.                 exclude_schemes = kwds['exclude_schemes']
  322.  
  323.         pk_args = (timeout, include_schemes, exclude_schemes)
  324.  
  325.         result = self._call_with_pk_and_fallback(use_pycups,
  326.                                                  'DevicesGet', pk_args,
  327.                                                  self._connection.getDevices,
  328.                                                  *args, **kwds)
  329.  
  330.         # return 'result' if fallback was called
  331.         if len (result.keys()) > 0 and type (result[result.keys()[0]]) == dict:
  332.              return result
  333.  
  334.         result_str = {}
  335.         if result != None:
  336.             for i in result.keys():
  337.                 if type(i) == dbus.String:
  338.                     result_str[str(i)] = str(result[i])
  339.                 else:
  340.                     result_str[i] = result[i]
  341.  
  342.         # cups-pk-helper returns all devices in one dictionary.
  343.         # Keys of different devices are distinguished by ':n' postfix.
  344.  
  345.         devices = {}
  346.         n = 0
  347.         postfix = ':' + str (n)
  348.         device_keys = [x for x in result_str.keys() if x.endswith(postfix)]
  349.         while len (device_keys) > 0:
  350.  
  351.             device_uri = None
  352.             device_dict = {}
  353.             for i in device_keys:
  354.                 key = i[:len(i) - len(postfix)]
  355.                 if key != 'device-uri':
  356.                     device_dict[key] = result_str[i]
  357.                 else:
  358.                     device_uri = result_str[i]
  359.  
  360.             if device_uri != None:
  361.                 devices[device_uri] = device_dict
  362.  
  363.             n += 1
  364.             postfix = ':' + str (n)
  365.             device_keys = [x for x in result_str.keys() if x.endswith(postfix)]
  366.  
  367.         return devices
  368.  
  369.  
  370. #    getJobs
  371. #    getJobAttributes
  372.  
  373.     def cancelJob(self, *args, **kwds):
  374.         (use_pycups, jobid) = self._args_to_tuple([int], *args)
  375.         pk_args = (jobid, )
  376.  
  377.         self._call_with_pk_and_fallback(use_pycups,
  378.                                         'JobCancel', pk_args,
  379.                                         self._connection.cancelJob,
  380.                                         *args, **kwds)
  381.  
  382.  
  383. #    cancelAllJobs
  384. #    authenticateJob
  385.     def setJobHoldUntil(self, *args, **kwds):
  386.         (use_pycups, jobid, job_hold_until) = self._args_to_tuple([int, str], *args)
  387.         pk_args = (jobid, job_hold_until, )
  388.  
  389.         self._call_with_pk_and_fallback(use_pycups,
  390.                                         'JobSetHoldUntil', pk_args,
  391.                                         self._connection.setJobHoldUntil,
  392.                                         *args, **kwds)
  393.  
  394.     def restartJob(self, *args, **kwds):
  395.         (use_pycups, jobid) = self._args_to_tuple([int], *args)
  396.         pk_args = (jobid, )
  397.         
  398.         self._call_with_pk_and_fallback(use_pycups,
  399.                                         'JobRestart', pk_args,
  400.                                         self._connection.restartJob,
  401.                                         *args, **kwds)
  402.  
  403.     def getFile(self, *args, **kwds):
  404.         ''' Keeping this as an alternative for the code.
  405.             We don't use it because it's not possible to know if the call was a
  406.             PK-one (and so we push the content of a temporary filename to fd or
  407.             file) or a non-PK-one (in which case nothing should be done).
  408.  
  409.                 filename = None
  410.                 fd = None
  411.                 file = None
  412.                 if use_pycups:
  413.                     if len(kwds) != 1:
  414.                         use_pycups = True
  415.                     elif kwds.has_key('filename'):
  416.                         filename = kwds['filename']
  417.                     elif kwds.has_key('fd'):
  418.                         fd = kwds['fd']
  419.                     elif kwds.has_key('file'):
  420.                         file = kwds['file']
  421.                     else:
  422.                         use_pycups = True
  423.  
  424.                     if fd or file:
  425.         '''
  426.  
  427.         file_object = None
  428.         fd = None
  429.         if len(args) == 2:
  430.             (use_pycups, resource, filename) = self._args_to_tuple([str, str], *args)
  431.         else:
  432.             (use_pycups, resource) = self._args_to_tuple([str], *args)
  433.             if kwds.has_key('filename'):
  434.                 filename = kwds['filename']
  435.             elif kwds.has_key('fd'):
  436.                 fd = kwds['fd']
  437.             elif kwds.has_key('file'):
  438.                 file_object = kwds['file']
  439.             else:
  440.                 if not use_pycups:
  441.                     raise TypeError()
  442.                 else:
  443.                     filename = None
  444.  
  445.         if (not use_pycups) and (fd != None or file_object != None):
  446.             (tmpfd, tmpfname) = tempfile.mkstemp()
  447.             os.close (tmpfd)
  448.  
  449.             pk_args = (resource, tmpfname)
  450.             self._call_with_pk_and_fallback(use_pycups,
  451.                                             'FileGet', pk_args,
  452.                                             self._connection.getFile,
  453.                                             *args, **kwds)
  454.  
  455.             tmpfd = os.open (tmpfname, os.O_RDONLY)
  456.             tmpfile = os.fdopen (tmpfd, 'r')
  457.             tmpfile.seek (0)
  458.  
  459.             if fd != None:
  460.                 os.lseek (fd, 0, os.SEEK_SET)
  461.                 line = tmpfile.readline()
  462.                 while line != '':
  463.                     os.write (fd, line)
  464.                     line = tmpfile.readline()
  465.             else:
  466.                 file_object.seek (0)
  467.                 line = tmpfile.readline()
  468.                 while line != '':
  469.                     file_object.write (line)
  470.                     line = tmpfile.readline()
  471.  
  472.             tmpfile.close ()
  473.             os.remove (tmpfname)
  474.         else:
  475.             pk_args = (resource, filename)
  476.  
  477.             self._call_with_pk_and_fallback(use_pycups,
  478.                                             'FileGet', pk_args,
  479.                                             self._connection.getFile,
  480.                                             *args, **kwds)
  481.  
  482.  
  483.     def putFile(self, *args, **kwds):
  484.         if len(args) == 2:
  485.             (use_pycups, resource, filename) = self._args_to_tuple([str, str], *args)
  486.         else:
  487.             (use_pycups, resource) = self._args_to_tuple([str], *args)
  488.             if kwds.has_key('filename'):
  489.                 filename = kwds['filename']
  490.             elif kwds.has_key('fd'):
  491.                 fd = kwds['fd']
  492.             elif kwds.has_key('file'):
  493.                 file_object = kwds['file']
  494.             else:
  495.                 if not use_pycups:
  496.                     raise TypeError()
  497.                 else:
  498.                     filename = None
  499.  
  500.         if (not use_pycups) and (fd != None or file_object != None):
  501.             (tmpfd, tmpfname) = tempfile.mkstemp()
  502.             os.lseek (tmpfd, 0, os.SEEK_SET)
  503.  
  504.             if fd != None:
  505.                 os.lseek (fd, 0, os.SEEK_SET)
  506.                 buf = os.read (fd, 512)
  507.                 while buf != '':
  508.                     os.write (tmpfd, buf)
  509.                     buf = os.read (fd, 512)
  510.             else:
  511.                 file_object.seek (0)
  512.                 line = file_object.readline ()
  513.                 while line != '':
  514.                     os.write (tmpfd, line)
  515.                     line = file_object.readline ()
  516.  
  517.             os.close (tmpfd)
  518.  
  519.             pk_args = (resource, tmpfname)
  520.  
  521.             self._call_with_pk_and_fallback(use_pycups,
  522.                                             'FilePut', pk_args,
  523.                                             self._connection.putFile,
  524.                                             *args, **kwds)
  525.  
  526.             os.remove (tmpfname)
  527.         else:
  528.  
  529.             pk_args = (resource, filename)
  530.  
  531.             self._call_with_pk_and_fallback(use_pycups,
  532.                                             'FilePut', pk_args,
  533.                                             self._connection.putFile,
  534.                                             *args, **kwds)
  535.  
  536.  
  537.     def addPrinter(self, *args, **kwds):
  538.         (use_pycups, name) = self._args_to_tuple([str], *args)
  539.         (filename, ppdname, info, location, device, ppd) = self._kwds_to_vars(['filename', 'ppdname', 'info', 'location', 'device', 'ppd'], **kwds)
  540.  
  541.         need_unlink = False
  542.         if not ppdname and not filename and ppd:
  543.             (fd, filename) = tempfile.mkstemp ()
  544.             ppd.writeFd(fd)
  545.             os.close(fd)
  546.             need_unlink = True
  547.  
  548.         if filename and not ppdname:
  549.             pk_args = (name, device, filename, info, location)
  550.             self._call_with_pk_and_fallback(use_pycups,
  551.                                             'PrinterAddWithPpdFile', pk_args,
  552.                                             self._connection.addPrinter,
  553.                                             *args, **kwds)
  554.             if need_unlink:
  555.                 os.unlink(filename)
  556.         else:
  557.             pk_args = (name, device, ppdname, info, location)
  558.             self._call_with_pk_and_fallback(use_pycups,
  559.                                             'PrinterAdd', pk_args,
  560.                                             self._connection.addPrinter,
  561.                                             *args, **kwds)
  562.  
  563.  
  564.     def setPrinterDevice(self, *args, **kwds):
  565.         (use_pycups, name, device) = self._args_to_tuple([str, str], *args)
  566.         pk_args = (name, device)
  567.  
  568.         self._call_with_pk_and_fallback(use_pycups,
  569.                                         'PrinterSetDevice', pk_args,
  570.                                         self._connection.setPrinterDevice,
  571.                                         *args, **kwds)
  572.  
  573.  
  574.     def setPrinterInfo(self, *args, **kwds):
  575.         (use_pycups, name, info) = self._args_to_tuple([str, str], *args)
  576.         pk_args = (name, info)
  577.  
  578.         self._call_with_pk_and_fallback(use_pycups,
  579.                                         'PrinterSetInfo', pk_args,
  580.                                         self._connection.setPrinterInfo,
  581.                                         *args, **kwds)
  582.  
  583.  
  584.     def setPrinterLocation(self, *args, **kwds):
  585.         (use_pycups, name, location) = self._args_to_tuple([str, str], *args)
  586.         pk_args = (name, location)
  587.  
  588.         self._call_with_pk_and_fallback(use_pycups,
  589.                                         'PrinterSetLocation', pk_args,
  590.                                         self._connection.setPrinterLocation,
  591.                                         *args, **kwds)
  592.  
  593.  
  594.     def setPrinterShared(self, *args, **kwds):
  595.         (use_pycups, name, shared) = self._args_to_tuple([str, bool], *args)
  596.         pk_args = (name, shared)
  597.  
  598.         self._call_with_pk_and_fallback(use_pycups,
  599.                                         'PrinterSetShared', pk_args,
  600.                                         self._connection.setPrinterShared,
  601.                                         *args, **kwds)
  602.  
  603.  
  604.     def setPrinterJobSheets(self, *args, **kwds):
  605.         (use_pycups, name, start, end) = self._args_to_tuple([str, str, str], *args)
  606.         pk_args = (name, start, end)
  607.  
  608.         self._call_with_pk_and_fallback(use_pycups,
  609.                                         'PrinterSetJobSheets', pk_args,
  610.                                         self._connection.setPrinterJobSheets,
  611.                                         *args, **kwds)
  612.  
  613.  
  614.     def setPrinterErrorPolicy(self, *args, **kwds):
  615.         (use_pycups, name, policy) = self._args_to_tuple([str, str], *args)
  616.         pk_args = (name, policy)
  617.  
  618.         self._call_with_pk_and_fallback(use_pycups,
  619.                                         'PrinterSetErrorPolicy', pk_args,
  620.                                         self._connection.setPrinterErrorPolicy,
  621.                                         *args, **kwds)
  622.  
  623.  
  624.     def setPrinterOpPolicy(self, *args, **kwds):
  625.         (use_pycups, name, policy) = self._args_to_tuple([str, str], *args)
  626.         pk_args = (name, policy)
  627.  
  628.         self._call_with_pk_and_fallback(use_pycups,
  629.                                         'PrinterSetOpPolicy', pk_args,
  630.                                         self._connection.setPrinterOpPolicy,
  631.                                         *args, **kwds)
  632.  
  633.  
  634.     def setPrinterUsersAllowed(self, *args, **kwds):
  635.         (use_pycups, name, users) = self._args_to_tuple([str, list], *args)
  636.         pk_args = (name, users)
  637.  
  638.         self._call_with_pk_and_fallback(use_pycups,
  639.                                         'PrinterSetUsersAllowed', pk_args,
  640.                                         self._connection.setPrinterUsersAllowed,
  641.                                         *args, **kwds)
  642.  
  643.  
  644.     def setPrinterUsersDenied(self, *args, **kwds):
  645.         (use_pycups, name, users) = self._args_to_tuple([str, list], *args)
  646.         pk_args = (name, users)
  647.  
  648.         self._call_with_pk_and_fallback(use_pycups,
  649.                                         'PrinterSetUsersDenied', pk_args,
  650.                                         self._connection.setPrinterUsersDenied,
  651.                                         *args, **kwds)
  652.  
  653.     def addPrinterOptionDefault(self, *args, **kwds):
  654.         # The values can be either a single string, or a list of strings, so
  655.         # we have to handle this
  656.         (use_pycups, name, option, value) = self._args_to_tuple([str, str, str], *args)
  657.         # success
  658.         if not use_pycups:
  659.             values = (value,)
  660.         # okay, maybe we directly have values
  661.         else:
  662.             (use_pycups, name, option, values) = self._args_to_tuple([str, str, list], *args)
  663.         pk_args = (name, option, values)
  664.  
  665.         self._call_with_pk_and_fallback(use_pycups,
  666.                                         'PrinterAddOptionDefault', pk_args,
  667.                                         self._connection.addPrinterOptionDefault,
  668.                                         *args, **kwds)
  669.  
  670.  
  671.     def deletePrinterOptionDefault(self, *args, **kwds):
  672.         (use_pycups, name, option) = self._args_to_tuple([str, str], *args)
  673.         pk_args = (name, option)
  674.  
  675.         self._call_with_pk_and_fallback(use_pycups,
  676.                                         'PrinterDeleteOptionDefault', pk_args,
  677.                                         self._connection.deletePrinterOptionDefault,
  678.                                         *args, **kwds)
  679.  
  680.  
  681.     def deletePrinter(self, *args, **kwds):
  682.         (use_pycups, name) = self._args_to_tuple([str], *args)
  683.         pk_args = (name,)
  684.  
  685.         self._call_with_pk_and_fallback(use_pycups,
  686.                                         'PrinterDelete', pk_args,
  687.                                         self._connection.deletePrinter,
  688.                                         *args, **kwds)
  689.  
  690. #    getPrinterAttributes
  691.  
  692.     def addPrinterToClass(self, *args, **kwds):
  693.         (use_pycups, printer, name) = self._args_to_tuple([str, str], *args)
  694.         pk_args = (name, printer)
  695.  
  696.         self._call_with_pk_and_fallback(use_pycups,
  697.                                         'ClassAddPrinter', pk_args,
  698.                                         self._connection.addPrinterToClass,
  699.                                         *args, **kwds)
  700.  
  701.  
  702.     def deletePrinterFromClass(self, *args, **kwds):
  703.         (use_pycups, printer, name) = self._args_to_tuple([str, str], *args)
  704.         pk_args = (name, printer)
  705.  
  706.         self._call_with_pk_and_fallback(use_pycups,
  707.                                         'ClassDeletePrinter', pk_args,
  708.                                         self._connection.deletePrinterFromClass,
  709.                                         *args, **kwds)
  710.  
  711.  
  712.     def deleteClass(self, *args, **kwds):
  713.         (use_pycups, name) = self._args_to_tuple([str], *args)
  714.         pk_args = (name,)
  715.  
  716.         self._call_with_pk_and_fallback(use_pycups,
  717.                                         'ClassDelete', pk_args,
  718.                                         self._connection.deleteClass,
  719.                                         *args, **kwds)
  720.  
  721. #    getDefault
  722.  
  723.     def setDefault(self, *args, **kwds):
  724.         (use_pycups, name) = self._args_to_tuple([str], *args)
  725.         pk_args = (name,)
  726.  
  727.         self._call_with_pk_and_fallback(use_pycups,
  728.                                         'PrinterSetDefault', pk_args,
  729.                                         self._connection.setDefault,
  730.                                         *args, **kwds)
  731.  
  732. #    getPPD
  733.  
  734.     def enablePrinter(self, *args, **kwds):
  735.         (use_pycups, name) = self._args_to_tuple([str], *args)
  736.         pk_args = (name, True)
  737.  
  738.         self._call_with_pk_and_fallback(use_pycups,
  739.                                         'PrinterSetEnabled', pk_args,
  740.                                         self._connection.enablePrinter,
  741.                                         *args, **kwds)
  742.  
  743.  
  744.     def disablePrinter(self, *args, **kwds):
  745.         (use_pycups, name) = self._args_to_tuple([str], *args)
  746.         pk_args = (name, False)
  747.  
  748.         self._call_with_pk_and_fallback(use_pycups,
  749.                                         'PrinterSetEnabled', pk_args,
  750.                                         self._connection.disablePrinter,
  751.                                         *args, **kwds)
  752.  
  753.  
  754.     def acceptJobs(self, *args, **kwds):
  755.         (use_pycups, name) = self._args_to_tuple([str], *args)
  756.         pk_args = (name, True, '')
  757.  
  758.         self._call_with_pk_and_fallback(use_pycups,
  759.                                         'PrinterSetAcceptJobs', pk_args,
  760.                                         self._connection.acceptJobs,
  761.                                         *args, **kwds)
  762.  
  763.  
  764.     def rejectJobs(self, *args, **kwds):
  765.         (use_pycups, name) = self._args_to_tuple([str], *args)
  766.         (reason,) = self._kwds_to_vars(['reason'], **kwds)
  767.         pk_args = (name, False, reason)
  768.  
  769.         self._call_with_pk_and_fallback(use_pycups,
  770.                                         'PrinterSetAcceptJobs', pk_args,
  771.                                         self._connection.rejectJobs,
  772.                                         *args, **kwds)
  773.  
  774.  
  775. #    printTestPage
  776.  
  777.     def adminGetServerSettings(self, *args, **kwds):
  778.         use_pycups = False
  779.         pk_args = ()
  780.  
  781.         result = self._call_with_pk_and_fallback(use_pycups,
  782.                                                'ServerGetSettings', pk_args,
  783.                                                self._connection.adminGetServerSettings,
  784.                                                *args, **kwds)
  785.         settings = {}
  786.         if result != None:
  787.             for i in result.keys():
  788.                 if type(i) == dbus.String:
  789.                     settings[str(i)] = str(result[i])
  790.                 else:
  791.                     settings[i] = result[i]
  792.  
  793.         return settings
  794.  
  795.  
  796.     def adminSetServerSettings(self, *args, **kwds):
  797.         (use_pycups, settings) = self._args_to_tuple([dict], *args)
  798.         pk_args = (settings,)
  799.  
  800.         self._call_with_pk_and_fallback(use_pycups,
  801.                                         'ServerSetSettings', pk_args,
  802.                                         self._connection.adminSetServerSettings,
  803.                                         *args, **kwds)
  804.  
  805.  
  806. #    getSubscriptions
  807. #    createSubscription
  808. #    getNotifications
  809. #    cancelSubscription
  810. #    renewSubscription
  811. #    printFile
  812. #    printFiles
  813.